<style type="text/css">
  .form-control {
    display: -webkit-inline-box;
    width: 30%;
  }
  label {
    width: 6%;
    text-align: right;
    margin-right: 10px;
  }
  input[type=file] {
    display: -webkit-inline-box;
  }
  .ct {
    margin-left: 6.8%;
  }
</style>
<br>
<div class="box box-primary">
  <div class="box-header with-border">
    <h3 class="box-title">新建商家</h3>
  </div>
  <!-- /.box-header -->
  <!-- form start -->
  <form id="theForm"  enctype="multipart/form-data">
    <div class="box-body">
      <div class="form-group">
        <label for="parents_id">父級商家</label>
        <span id="parents_id"></span>
      </div>
      <div class="form-group">
        <label for="business_name">商家姓名</label>
        <input type="text" class="form-control" name="business_name" placeholder="汉字、字符、数字" value="">
      </div>
      <div class="form-group">
        <label for="username">登录名</label>
        <input type="text" class="form-control" name="username" placeholder="字符、数字" value="">
      </div>
      <div class="form-group">
        <label for="password">密码</label>
        <input type="password" class="form-control" name="password" placeholder="6位以上" value="">
      </div>

      <div class="form-group">
        <label for="sales">优惠活动</label>
        <input type="text" class="form-control" name="sales" placeholder="优惠活动" value="">
      </div>

      <div class="form-group">
        <label for="mobile">手机号</label>
        <input type="text" class="form-control" name="mobile" placeholder="手机号" value="">
      </div>

      <div class="form-group">
        <label for="category_id">分类</label>
        <input type="text" class="form-control" name="category_id" placeholder="分类" value="">
      </div>

<!--       <div class="form-group">
        <label for="area_id">区域</label>
        <span id="area_id"></span>
      </div> -->
      <div class="form-group">
        <label for="address">地址</label>
        <input type="text" class="form-control" name="address" placeholder="地址" value="">
      </div>
      <div class="form-group">
        <label for="traffic">交通信息</label>
        <input type="text" class="form-control" name="traffic" placeholder="交通信息" value="">
      </div>
      <div class="form-group">
        <label for="longitude">经度</label>
        <input type="text" class="form-control" name="longitude" placeholder="经度" value="">
      </div>
      <div class="form-group">
        <label for="latitude">纬度</label>
        <input type="text" class="form-control" name="latitude" placeholder="纬度" value="">
      </div>

      <div class="form-group">
        <label for="description">描述</label>
        <input type="text" class="form-control" name="description" placeholder="描述" value="">
      </div>
      <div class="form-group">
        <label for="logo">商家LOGO</label>
        <input type="file" name="logo" id="logo" class="upload">
        <input type="input" id="picture" hidden="true" name="picture">
        <p class="help-block"></p>
      </div>
    </div>
    <!-- /.box-body -->

    <div class="box-footer">
      <div  class="btn btn-primary ct" onclick="createbusiness()">创建</div>
    </div>
  </form>
</div>
<script type="text/javascript">
  var field = "parents_id";
  var param = {};
  param.action = 'goods_list';
  param.bid    = window.localStorage.getItem("bid"); 
  param.token    = window.localStorage.getItem("token");
  commonAjax('getbusiness',5,field,param);

  // var field = "area_id";
  // commonAjax('getarea',5,field);

  function createbusiness()
  {
    var action = 'subbusiness';
    var bid    = window.localStorage.getItem("bid"); 
    var token    = window.localStorage.getItem("token");
    var url = getapi(action);

    var formdata = new FormData($("#theForm")[0]);
    formdata.append('logo', $('#logo')[0].files[0]);
    formdata.append('bid', bid);
    formdata.append('token', token);
    var jumpurl = "businesslist";
    postFormDataAjax(url,formdata,jumpurl,Assignment=0);
  }

  $(".upload").change(function(){    
    var action = 'upload';
    var url = getapi(action)+'&bid='+window.localStorage.getItem("bid")+'&token='+window.localStorage.getItem("token"); 
    var Assignment = 'picture';

    var formdata = new FormData();
    formdata.append('logo', $('#logo')[0].files[0]);

    // console.log(formdata.get("logo"));
    postFormDataAjax(url,formdata,jumpurl=0,Assignment);
  });
</script>